package com.ball.common.utils;

public class ValidatorUtils {


    // 正则表达式规则
    private static final String USERNAME_PATTERN = "^[a-zA-Z0-9]{6,15}$";
    private static final String PASSWORD_PATTERN = "^[a-zA-Z0-9.,:\"'|\\\\/!@#$%^&*?()_+\\-=~;]{6,15}$";

    // 验证账号
    public static boolean validateAccount(String username) {
        return username != null && username.matches(USERNAME_PATTERN);
    }

    // 验证密码
    public static boolean validatePassword(String password) {
        if (password == null || !password.matches(PASSWORD_PATTERN)) {
            return false;
        }

        boolean hasLetter = false;
        boolean hasDigit = false;
        boolean hasSpecial = false;

        for (char ch : password.toCharArray()) {
            if (Character.isLetter(ch)) {
                hasLetter = true;
            } else if (Character.isDigit(ch)) {
                hasDigit = true;
            } else {
                hasSpecial = true;
            }

            if ((hasLetter && hasDigit) || (hasLetter && hasSpecial) || (hasDigit && hasSpecial)) {
                return true;
            }
        }

        return false;
    }

    public static void main(String[] args) {
        // 测试示例
        System.out.println("Username '1233333' valid: " + validateAccount("User123"));
        System.out.println("Password 'Pass....' valid: " + validatePassword("Pass#123"));
    }
}